package com.irdstudio.efp.esb.api.rest.psd.notice;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.ser.Serializers;
import com.irdstudio.basic.framework.core.constant.BaseConstant;
import com.irdstudio.basic.framework.core.constant.ESBConstant;
import com.irdstudio.basic.framework.core.constant.EsbRetCodeStandard;
import com.irdstudio.basic.framework.core.exception.BizException;
import com.irdstudio.basic.framework.core.exception.ESBException;
import com.irdstudio.basic.framework.core.util.DateTool;
import com.irdstudio.basic.framework.core.util.DateUtility;
import com.irdstudio.efp.console.common.psd.PsdEnumSet;
import com.irdstudio.efp.console.service.facade.PubSysInfoService;
import com.irdstudio.efp.esb.api.bean.psd.notice.req.NlsPsdPreCreditResultNoticeReqBean;
import com.irdstudio.efp.esb.api.bean.psd.notice.resp.NlsPsdPreCreditResultNoticeRespBean;
import com.irdstudio.efp.esb.api.common.EsbRespServiceBeanCreator;
import com.irdstudio.efp.esb.api.common.GroupeInterface;
import com.irdstudio.efp.esb.api.rest.EsbController;
import com.irdstudio.efp.esb.common.constant.EsbBizEnums;
import com.irdstudio.efp.esb.common.constant.EsbSysHeadEnums;
import com.irdstudio.efp.esb.common.constant.MsLoanConstant;
import com.irdstudio.efp.esb.common.constant.esb.EsbNlsTrmTypeEnum;
import com.irdstudio.efp.esb.common.server.req.EsbReqServiceBean;
import com.irdstudio.efp.esb.common.server.resp.EsbRespServiceBean;
import com.irdstudio.efp.nls.common.constant.sed.SedNlsEnum;
import com.irdstudio.efp.nls.service.facade.NlsPublicService;
import com.irdstudio.efp.nls.service.facade.psd.PreNlsCreditInfoService;
import com.irdstudio.efp.nls.service.vo.psd.PreNlsCreditInfoVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * 需求编号：【2019D1218】（普税贷需求）
 * 问题编号：【2019D1218】（预授信结果通知处理）
 * 开发人员：【ludayong】
 * 创建日期：【2019/12/16 10:11】
 * 功能描述：
 */

@RestController
@RequestMapping("esb")
public class NlsPsdPreCreditResultNoticeController implements EsbController {
    /**
     * 日志信息
     */
    private final Logger logger = LoggerFactory.getLogger(NlsPsdPreCreditResultNoticeController.class);

    @Autowired
    @Qualifier("nlsPublicService")
    private NlsPublicService nlsPublicService;

    @PostMapping("/SERVICE_30220009_06")
    public EsbRespServiceBean doRecv(@Validated @ModelAttribute("esbReqServiceBean") EsbReqServiceBean esbReqServiceBean, BindingResult bindingResult1,
                                     @Validated({GroupeInterface.psd.class}) @ModelAttribute("nlsPsdPreCreditResultNoticeReqBean") NlsPsdPreCreditResultNoticeReqBean nlsPsdPreCreditResultNoticeReqBean, BindingResult bindingResult2, Exception exception) {
        //  预授信申请流水号
        String preCrAppSrlNo = nlsPsdPreCreditResultNoticeReqBean.getPreCrAppSrlNo();
        // 预授信结果通知处理响应信息
        NlsPsdPreCreditResultNoticeRespBean nlsPsdPreCreditResultNoticeRespBean = new NlsPsdPreCreditResultNoticeRespBean();
        try {
            logger.info("======>调用接口【" + preCrAppSrlNo + "_30220009_06】开始<======");
            // 参数校验
            validateBean(esbReqServiceBean, bindingResult1, nlsPsdPreCreditResultNoticeReqBean, bindingResult2, exception, logger);
            // 全局关联流水号
            String glblSrlNo = esbReqServiceBean.getSysHead().getGlblSrlNo();
            // 设置系统头对象
            setSysHeadFieldThreadLocal(esbReqServiceBean);

            // 预授信申请信息入参
            PreNlsCreditInfoVO inPreNlsCreditInfoVo = new PreNlsCreditInfoVO();
            // 预授信申请流水号
            inPreNlsCreditInfoVo.setApplySeq(preCrAppSrlNo);
            // 预授信申请信息查询信息
            PreNlsCreditInfoVO queryPreNlsCreditInfoVo = preNlsCreditInfoService.queryByPk(inPreNlsCreditInfoVo);

            if (Objects.isNull(queryPreNlsCreditInfoVo)) {
                throw new BizException(EsbBizEnums.RetCodeEnum.FAILURE.getVALUE(), "预授信申请信息" + "【" + preCrAppSrlNo + "】为空！");
            }
            //预授信申请记录非处理中状态
            if (MsLoanConstant.NlsApplyStateEnum.PASS.getVALUE().equals(queryPreNlsCreditInfoVo.getStatus())
                    || MsLoanConstant.NlsApplyStateEnum.REJECT.getVALUE().equals(queryPreNlsCreditInfoVo.getStatus())) {
                return failureNotHandle(esbReqServiceBean, nlsPsdPreCreditResultNoticeReqBean, nlsPsdPreCreditResultNoticeRespBean, new BizException(EsbBizEnums.RetCodeEnum.FAILURE.getVALUE(), "预授信审批结果重复通知！"), EsbRetCodeStandard.WFJKYWGZ);
            }
            // 执行普税贷预授信结果通知返回报文
            return successHandler(esbReqServiceBean, nlsPsdPreCreditResultNoticeReqBean, nlsPsdPreCreditResultNoticeRespBean, queryPreNlsCreditInfoVo);
        } catch (ESBException e) {
            logger.error("普税贷预授信结果通知处理接口出现异常，异常信息：", e);
            e.printStackTrace();
            return failureHandler(esbReqServiceBean, nlsPsdPreCreditResultNoticeReqBean, nlsPsdPreCreditResultNoticeRespBean, e, EsbRetCodeStandard.JKYDCSJYBTG);
        } catch (BizException e) {
            logger.error("普税贷预授信结果通知处理接口出现异常，异常信息：", e);
            e.printStackTrace();
            return failureHandler(esbReqServiceBean, nlsPsdPreCreditResultNoticeReqBean, nlsPsdPreCreditResultNoticeRespBean, e, EsbRetCodeStandard.WFJKYWGZ);
        } catch (Exception e) {
            logger.error("普税贷预授信结果通知处理接口出现异常，异常信息：", e);
            e.printStackTrace();
            return failureHandler(esbReqServiceBean, nlsPsdPreCreditResultNoticeReqBean, nlsPsdPreCreditResultNoticeRespBean, e, EsbRetCodeStandard.SJCLYC);
        } finally {
            logger.info("======>调用接口【" + preCrAppSrlNo + "_30220009_06】结束<======");
        }
    }

    @ModelAttribute("esbReqServiceBean")
    public EsbReqServiceBean getReqEsbHeadBean(HttpServletRequest request) {
        logger.info("获取ESB请求系统头和请求应用头对象!");
        EsbReqServiceBean esbReqServiceBean = (EsbReqServiceBean) request.getAttribute("esbReqServiceBean");
        return esbReqServiceBean;
    }

    @ModelAttribute("nlsPsdPreCreditResultNoticeReqBean")
    public NlsPsdPreCreditResultNoticeReqBean getReqEsbBodyBean(HttpServletRequest request) {
        logger.info("获取ESB请求体！");
        String esbReqBody = (String) request.getAttribute("esbReqBody");
        return JSONObject.parseObject(esbReqBody, NlsPsdPreCreditResultNoticeReqBean.class);
    }

    /**
     * 需求编号：【2019D1218】（普税贷需求）
     * 问题编号：【2019D1218】（普税贷预授信结果通知处理接口成功返回信息）
     * 开发人员：【ludayong】
     * 创建日期：【2019/12/16 15:35】
     * 功能描述：
     * 修改日期：【2019/12/16 15:35】
     * 修改描述：
     */
    public EsbRespServiceBean successHandler(EsbReqServiceBean esbReqServiceBean, NlsPsdPreCreditResultNoticeReqBean nlsPsdPreCreditResultNoticeReqBean, NlsPsdPreCreditResultNoticeRespBean nlsPsdPreCreditResultNoticeRespBean, PreNlsCreditInfoVO queryPreNlsCreditInfoVo) throws Exception {
        // 三个月内是否重复申请
        // Boolean isRepAppFlag = validateRepApp(nlsPsdPreCreditResultNoticeReqBean);
        // 审批结果标志
        queryPreNlsCreditInfoVo.setApprovalResultMark(nlsPsdPreCreditResultNoticeReqBean.getAprvlRsltFlg());
        // 审批状态
        if (PsdEnumSet.AprvlRsltFlgEnum.PASS.getValue().equals(nlsPsdPreCreditResultNoticeReqBean.getAprvlRsltFlg()) /*&& !isRepAppFlag*/) {
            queryPreNlsCreditInfoVo.setStatus(MsLoanConstant.NlsApplyStateEnum.PASS.getVALUE());
            //
        } else {
            queryPreNlsCreditInfoVo.setStatus(MsLoanConstant.NlsApplyStateEnum.REJECT.getVALUE());
        }
        // 授信建议额度
        Double crRcmndnAmt = Optional.ofNullable(nlsPsdPreCreditResultNoticeReqBean.getCrRcmndnAmt()).orElse(0.0);
        queryPreNlsCreditInfoVo.setReAmount(new BigDecimal(crRcmndnAmt));
        // 建议年利率
        Double prpslAnulIntRt = Optional.ofNullable(nlsPsdPreCreditResultNoticeReqBean.getPrpslAnulIntRt()).orElse(0.0);
        queryPreNlsCreditInfoVo.setReYRate(new BigDecimal(prpslAnulIntRt));
        if (PsdEnumSet.AprvlRsltFlgEnum.PASS.getValue().equals(nlsPsdPreCreditResultNoticeReqBean.getAprvlRsltFlg())) {
            // 授信期限
            queryPreNlsCreditInfoVo.setCreditPeriod(CREDIT_PERIOD);
            // 授信期限单位
            queryPreNlsCreditInfoVo.setCreditPeriodUnit(EsbNlsTrmTypeEnum.M.getValue());

            //将其它预授信申请数据修改为失效状态
            updateOtherStatus(queryPreNlsCreditInfoVo);
        }
        // 风控审批失败时拒绝原因赋值：准入失败
        if (PsdEnumSet.AprvlRsltFlgEnum.REFUSE.getValue().equals(nlsPsdPreCreditResultNoticeReqBean.getAprvlRsltFlg())) {
            // 拒绝原因
            queryPreNlsCreditInfoVo.setRefuseReason("准入失败！");
            // 拒绝码
            queryPreNlsCreditInfoVo.setRefuseCode("999999");
        }
        // 社会信用统一代码
        queryPreNlsCreditInfoVo.setSocialCreditCode(nlsPsdPreCreditResultNoticeReqBean.getSoclCrdtCd());
        // 企业名称
        queryPreNlsCreditInfoVo.setEnterpriseName(nlsPsdPreCreditResultNoticeReqBean.getEntpNm());
        // 法定代表人证件号
        queryPreNlsCreditInfoVo.setCertNo(nlsPsdPreCreditResultNoticeReqBean.getCertNo());
        // 法定代表人手机号
        queryPreNlsCreditInfoVo.setMobileNo(nlsPsdPreCreditResultNoticeReqBean.getMblNo());
        // 法定代表人姓名
        queryPreNlsCreditInfoVo.setCertName(nlsPsdPreCreditResultNoticeReqBean.getIdentNm());
        // 法定代表人证件类型
        queryPreNlsCreditInfoVo.setCertType(nlsPsdPreCreditResultNoticeReqBean.getIdentTp());
        // 审批时间
        queryPreNlsCreditInfoVo.setApprovalTime(pubSysInfoService.getOpenday(BaseConstant.SYS_ID_1001) + " 00:00:00");
        // 风控审批失败时拒绝原因赋值：系统异常，请稍后重试！
        if (PsdEnumSet.AprvlRsltFlgEnum.EXCEPTION.getValue().equals(nlsPsdPreCreditResultNoticeReqBean.getAprvlRsltFlg())) {
            // 三个月重复申请标识
            queryPreNlsCreditInfoVo.setRepAppFlag(SedNlsEnum.YesOrNo.NO.getValue());
            // 拒绝原因
            queryPreNlsCreditInfoVo.setRefuseReason("系统异常，请稍后重试！如有疑问请咨询96699");
            // 拒绝码
            queryPreNlsCreditInfoVo.setRefuseCode("999999");
        } /*else if (isRepAppFlag) {
            // 三个月重复申请标识
            queryPreNlsCreditInfoVo.setRepAppFlag(SedNlsEnum.YesOrNo.NO.getValue());
            // 拒绝原因
            String msg = "在三个月内重复申请！";
            queryPreNlsCreditInfoVo.setRefuseReason(msg);
            // 拒绝码
            queryPreNlsCreditInfoVo.setRefuseCode(EsbRetCodeStandard.WFJKYWGZ.getValue());
        }*/
        // 风控审批拒绝原因
        queryPreNlsCreditInfoVo.setAppRefuseReason(nlsPsdPreCreditResultNoticeReqBean.getRfsRsn());
        // 风控审批拒绝码
        queryPreNlsCreditInfoVo.setAppRefuseCode(nlsPsdPreCreditResultNoticeReqBean.getRfsCd());
        // 最后更新人
        queryPreNlsCreditInfoVo.setLastUpdateUser(BaseConstant.ADMIN);
        // 最后更新时间
        queryPreNlsCreditInfoVo.setLastUpdateTime(DateTool.getCurrentDateTime());
        // 行业
        queryPreNlsCreditInfoVo.setIndustry(nlsPsdPreCreditResultNoticeReqBean.getIdyCgy());
        // 企业注册地
        queryPreNlsCreditInfoVo.setRegistration(getRegistrationByCode(nlsPsdPreCreditResultNoticeReqBean.getBckpFld2(), queryPreNlsCreditInfoVo.getRegistration()));
        //
        queryPreNlsCreditInfoVo.setBkColumn2(nlsPsdPreCreditResultNoticeReqBean.getBckpFld2());
        // 更预授信申请信息
        int num = preNlsCreditInfoService.updateByPk(queryPreNlsCreditInfoVo);

        if (num == -1) {
            throw new BizException("更新预授信申请信息失败!");
        } else {
            // 返回代码
            nlsPsdPreCreditResultNoticeRespBean.setRetCd(ESBConstant.SUCCESS);
            // 返回信息
            nlsPsdPreCreditResultNoticeRespBean.setRetMsg(EsbBizEnums.RetCodeMsg.SUCCESS_MSG.getVALUE());
        }

        // 下发短信
        nlsPublicService.sendPsdPreApproveMessage(queryPreNlsCreditInfoVo.getMobileNo(), nlsPsdPreCreditResultNoticeReqBean.getAprvlRsltFlg(), String.valueOf(queryPreNlsCreditInfoVo.getReAmount()));

        return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
                JSONObject.toJSONString(nlsPsdPreCreditResultNoticeRespBean, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero),
                EsbSysHeadEnums.RetStEnum.SUCCESS.getCode(),
                EsbBizEnums.RetCodeEnum.SUCCESS.getVALUE(),
                EsbBizEnums.RetCodeMsg.SUCCESS_MSG.getVALUE());
    }

    /**
     * 根据风控返回来的企业注册地码值获取企业注册地
     *
     * @param code
     * @return
     */
    private String getRegistrationByCode(String code, String oldRegistration) {

        if (StringUtils.isNotEmpty(code)) {
            //这里做转换
            //城市	税务机构代码
            //广州
            if ("4401".equals(code)) {
                return "广州";
            }
            //深圳
            if ("4403".equals(code)) {
                return "深圳";
            }
            //佛山
            if ("4406".equals(code)) {
                return "佛山";
            }
            //东莞
            if ("4419".equals(code)) {
                return "东莞";
            }
            //中山
            if ("4420".equals(code)) {
                return "中山";
            }
            //惠州
            if ("4413".equals(code)) {
                return "惠州";
            }
            //江门
            if ("4407".equals(code)) {
                return "江门";
            }
            //珠海
            if ("4404".equals(code)) {
                return "珠海";
            }
            //清远
            if ("4418".equals(code)) {
                return "清远";
            }
            //肇庆
            if ("4412".equals(code)) {
                return "肇庆";
            }
        }
        return oldRegistration;
    }

    /**
     * 将其它数据的状态置为失效状态
     *
     * @param queryPreNlsCreditInfoVo
     * @throws Exception
     */
    private void updateOtherStatus(PreNlsCreditInfoVO queryPreNlsCreditInfoVo) throws Exception {
        //根据纳税识别号查询出预授信申请记录
        List<PreNlsCreditInfoVO> preNlsCreditInfoVOS = preNlsCreditInfoService.queryByTaxNumber(queryPreNlsCreditInfoVo.getTaxIdentificationNumber());
        if (!preNlsCreditInfoVOS.isEmpty()) {
            for (PreNlsCreditInfoVO preNlsCreditInfoVO : preNlsCreditInfoVOS) {
                if (preNlsCreditInfoVO.getApplySeq().equals(queryPreNlsCreditInfoVo.getApplySeq())) {
                    continue;
                }
                LocalDateTime createTime1 = LocalDateTime.parse(queryPreNlsCreditInfoVo.getCreateTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
                LocalDateTime createTime2 = LocalDateTime.parse(preNlsCreditInfoVO.getCreateTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
                //如果时间2在时间1后面，则不做处理
                if (createTime2.isAfter(createTime1)) {
                    continue;
                }
                if (!"02".equals(preNlsCreditInfoVO.getStatus())) {
                    continue;
                }
                //置为失效
                preNlsCreditInfoVO.setStatus("06");
                preNlsCreditInfoService.updateByPk(preNlsCreditInfoVO);
            }
        }
    }

    /**
     * 需求编号：【2019D1218】（普税贷需求）
     * 问题编号：【2019D1218】（普税贷预授信结果通知处理接口失败返回信息）
     * 开发人员：【ludayong】
     * 创建日期：【2019/12/16 15:24】
     * 功能描述：
     * 修改日期：【2019/12/16 15:24】
     * 修改描述：
     */
    public EsbRespServiceBean failureHandler(EsbReqServiceBean esbReqServiceBean, NlsPsdPreCreditResultNoticeReqBean nlsPsdPreCreditResultNoticeReqBean, NlsPsdPreCreditResultNoticeRespBean nlsPsdPreCreditResultNoticeRespBean, Exception exception, EsbRetCodeStandard esbRetCodeStandard) {
        PreNlsCreditInfoVO inPreNlsCreditInfoVo = new PreNlsCreditInfoVO();
        // 预授信申请流水号
        String applySeq = nlsPsdPreCreditResultNoticeReqBean.getPreCrAppSrlNo();
        // 预授信申请流水号
        inPreNlsCreditInfoVo.setApplySeq(applySeq);
        // 渠道申请号
        inPreNlsCreditInfoVo.setChannelApplyNo(applySeq);
        // 审批状态
        inPreNlsCreditInfoVo.setStatus(MsLoanConstant.NlsApplyStateEnum.REJECT.getVALUE());
        // 拒绝原因
        inPreNlsCreditInfoVo.setRefuseReason(exception.getLocalizedMessage());
        // 拒绝码
        inPreNlsCreditInfoVo.setRefuseCode(esbRetCodeStandard.getValue());
        // 审批时间--营业日期
        //inPreNlsCreditInfoVo.setApprovalTime(DateTool.getCurrentDateTime());
        inPreNlsCreditInfoVo.setApprovalTime(pubSysInfoService.getOpenday(BaseConstant.SYS_ID_1001) + " 00:00:00");
        // 最后更新人
        inPreNlsCreditInfoVo.setLastUpdateUser(BaseConstant.ADMIN);
        // 最后更新时间 -- 可以作为审批时间（服务器使用）
        inPreNlsCreditInfoVo.setLastUpdateTime(DateTool.getCurrentDateTime());
        // 更预授信申请信息
        preNlsCreditInfoService.updateByPk(inPreNlsCreditInfoVo);

        logger.error("普税贷贷预授信结果通知处理接口出现异常，异常信息：" + exception.getMessage());
        nlsPsdPreCreditResultNoticeRespBean.setRetCd(esbRetCodeStandard.getValue());
        nlsPsdPreCreditResultNoticeRespBean.setRetMsg(exception.getMessage());
        exception.printStackTrace();
        return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
                JSONObject.toJSONString(nlsPsdPreCreditResultNoticeRespBean, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteMapNullValue),
                EsbSysHeadEnums.RetStEnum.FAILURE.getCode(),
                esbRetCodeStandard.getValue(),
                exception.getMessage());
    }

    /**
     * 需求编号：【2019D1218】（普税贷需求）
     * 问题编号：【2019D1218】（普税贷预授信结果通知处理接口失败返回信息）
     * 开发人员：【ludayong】
     * 创建日期：【2019/12/16 15:24】
     * 功能描述：
     * 修改日期：【2019/12/16 15:24】
     * 修改描述：
     */
    public EsbRespServiceBean failureNotHandle(EsbReqServiceBean esbReqServiceBean, NlsPsdPreCreditResultNoticeReqBean nlsPsdPreCreditResultNoticeReqBean, NlsPsdPreCreditResultNoticeRespBean nlsPsdPreCreditResultNoticeRespBean, Exception exception, EsbRetCodeStandard esbRetCodeStandard) {
        logger.error("普税贷贷预授信结果通知处理接口出现异常，异常信息：" + exception.getMessage());
        nlsPsdPreCreditResultNoticeRespBean.setRetCd(esbRetCodeStandard.getValue());
        nlsPsdPreCreditResultNoticeRespBean.setRetMsg(exception.getMessage());
        exception.printStackTrace();
        return EsbRespServiceBeanCreator.buildesbRespServiceBean(esbReqServiceBean,
                JSONObject.toJSONString(nlsPsdPreCreditResultNoticeRespBean, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteMapNullValue),
                EsbSysHeadEnums.RetStEnum.FAILURE.getCode(),
                esbRetCodeStandard.getValue(),
                exception.getMessage());
    }

    /**
     * 需求编号：【2019D1218】（普税贷需求）
     * 问题编号：【2019D1218】（预授信三个月内不能重复申请）
     * 开发人员：【ludayong】
     * 创建日期：【2020/4/1 16:29】
     * 功能描述：
     * 修改日期：【2020/4/1 16:29】
     * 修改描述：
     */
    private Boolean validateRepApp(NlsPsdPreCreditResultNoticeReqBean nlsPsdPreCreditResultNoticeReqBean) throws Exception {
        // 三个月内是否重复申请
        Boolean isRepAppFlag = false;
        // 三个月内不能重复申请。如是，则审批拒绝
        PreNlsCreditInfoVO inPreCreditInfoByCertInfo = new PreNlsCreditInfoVO();
        // 法定代表人证件号
        inPreCreditInfoByCertInfo.setCertNo(nlsPsdPreCreditResultNoticeReqBean.getCertNo());
        // 法定代表人证件号
        inPreCreditInfoByCertInfo.setCertType(nlsPsdPreCreditResultNoticeReqBean.getIdentTp());
        // 预授信申请信息查询信息
        List<PreNlsCreditInfoVO> preCreditList = preNlsCreditInfoService.queryByCertInfoAndApplyDate(inPreCreditInfoByCertInfo);
        if (Objects.nonNull(preCreditList) && !preCreditList.isEmpty()) {
            // 三个月重复申请标识
            isRepAppFlag = true;
        }
        return isRepAppFlag;
    }

    //预授信申请信息表服务
    @Autowired
    @Qualifier("preNlsCreditInfoService")
    private PreNlsCreditInfoService preNlsCreditInfoService;

    @Autowired
    private PubSysInfoService pubSysInfoService;

    // 授信期限
    private static final String CREDIT_PERIOD = "12";
}